package com.societyGames.flashForms
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	public class CenterContainer extends SingleChildContainer
	{
		private var _desiredWidth:Number;
		private var _desiredHeight:Number;
		
		public override function set width(value:Number):void
		{	
			this._desiredWidth = value;
			recalculate();
		}
		
		public override function set height(value:Number):void
		{	
			this._desiredHeight = value;
			recalculate();
		}

		protected override function childSizeChangedHandler(event:Event):void
		{
			recalculate();
		}
		
		private function recalculate():void
		{
			if (this._child != null)
			{
				this._child.x = (this._desiredWidth - this._child.width) / 2;
				this._child.y = (this._desiredHeight - this._child.height) / 2;
			}
		}
	}
}